<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>员工列表页面</h1>
<table border="1">
  <tr>
    <th>id</th>
    <th>名字</th>
    <th>工作</th>
    <th>年龄</th>
    <th>工资</th>
    <th>操作</th>
  </tr>
  <tr v-for="emp in arr">
    <td>{{emp.id}}</td>
    <!--如果在属性里面需要用到Vue相关变量内容 需要使用属性绑定-->
    <td><a :href="'/update.html?id='+emp.id">{{emp.name}}</a></td>
    <td>{{emp.job}}</td>
    <td>{{emp.age}}</td>
    <td>{{emp.salary}}</td>
    <td><a href="javascript:void (0)" @click="del(emp.id)">删除</a></td>
  </tr>
</table>
<!--引入axios和vue-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
<script>
  let v = new Vue({
    el:"table",
    data:{
      arr:[]
    },
      created:function () {//创建完页面需要做的事,写在此方法中
        axios.get("/select").then(function (response) {
          v.arr = response.data;
        })
    },
    methods:{
      del:function (id) {
        if(confirm("您确认删除吗?")){
          //发出删除请求
          axios.get("/delete?id="+id).then(function () {
            //删除完之后刷新页面
            location.reload();
          })
        }
      }
    }
  })
</script>
</body>
</html>